package de.uni.muenster.idw2.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.Gallery;
import android.widget.ImageView;
import de.uni.muenster.idw2.data.MyImage;

public class MyPhotoView extends ImageView {

	private MyImage photo;
	private Paint yellowRoute = new Paint();

	public MyPhotoView(Context context, MyImage photo) {
		super(context);
		this.photo = photo;
		this.setImageDrawable(photo.getDrawable());
		
		// set the ImageView bounds to match the Drawable's dimensions
		this.setAdjustViewBounds(true); 
		this.setLayoutParams(new Gallery.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

		// Configure the paint
		yellowRoute.setColor(Color.YELLOW);
		yellowRoute.setDither(true);
		yellowRoute.setStyle(Paint.Style.STROKE);
		yellowRoute.setStrokeJoin(Paint.Join.ROUND);
		yellowRoute.setStrokeCap(Paint.Cap.ROUND);
		yellowRoute.setStrokeWidth(6);

	}

	@Override
	public void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.save();

		this.setImageDrawable(photo.getDrawable());

		Path path = new Path();
		path.moveTo(photo.getPoints()[0].getRelX() * this.getWidth(),
				photo.getPoints()[0].getRelY() * this.getHeight());
		path.lineTo(photo.getPoints()[0].getRelX() * this.getWidth(),
				photo.getPoints()[0].getRelY() * this.getHeight());

		for (int i = 1; i < photo.getPoints().length; i++) {
			path.lineTo(photo.getPoints()[i].getRelX() * this.getWidth(),
					photo.getPoints()[i].getRelY() * this.getHeight());
		}
		
		canvas.drawPath(path, yellowRoute);
		Log.d("ANALYSIS", "mpvHeight2 = " + this.getHeight());
		Log.d("ANALYSIS", "mpvHeight2 = " + this.getWidth());
		canvas.restore();
	}
}
